package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ49_贪心的商人 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/49.txt"));
        int numbers = in.nextInt();
        int days = in.nextInt();
        int[] item = new int[numbers];
        int[][] goodsPrice = new int[numbers][days];
        for (int i = 0; i < numbers; i++) {
            item[i] = in.nextInt();
        }
        for (int i = 0; i < numbers; i++) {
            for (int j = 0; j < days; j++) {
                goodsPrice[i][j] = in.nextInt();
            }
        }
        int res = 0;
        for (int i = 0; i < numbers; i++) {
            for (int j = 1; j < days; j++) {
                if (goodsPrice[i][j] > goodsPrice[i][j - 1]) {
                    res += (goodsPrice[i][j] - goodsPrice[i][j - 1]) * item[i];
                }
            }
        }
        System.out.println(res);
    }
}
